import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart' hide Action;
import 'package:www.znpigai.teacher/global_store/state.dart';

import 'state.dart';

Widget buildView(
    SubjectTabState state, Dispatch dispatch, ViewService viewService) {
  List<DropdownMenuItem> typeItemList() {
    final List<DropdownMenuItem> items = List();
    GlobalState.types.forEach((key, value) {
      items.add(DropdownMenuItem(value: key, child: Text(value)));
    });
    return items;
  }

  List<DropdownMenuItem> gradeItemList() {
    final List<DropdownMenuItem> items = List();
    GlobalState.grades.forEach((key, value) {
      items.add(DropdownMenuItem(value: key, child: Text(value)));
    });
    return items;
  }

  var tabBar = TabBar(
    isScrollable: false,
    labelColor: Colors.blue,
    indicatorColor: Colors.blue,
    indicatorPadding: EdgeInsets.symmetric(horizontal: 60),
    indicatorWeight: 3,
    tabs: state.tabs,
    controller: state.tabController,
  );

  var appBar = AppBar(
    centerTitle: true,
    elevation: 2.0,
    backgroundColor: Colors.white,
    title: Text(
      '题库选择',
      style: TextStyle(color: Colors.black54, fontSize: 18),
    ),
    bottom: tabBar,
  );

  return Scaffold(
    appBar: state.isPage ? appBar : tabBar,
    body: TabBarView(
      controller: state.tabController,
      children: <Widget>[
        Column(
          children: <Widget>[
            Row(
              mainAxisSize: MainAxisSize.max,
              children: <Widget>[
                SizedBox(width: 10),
                Expanded(
                  flex: 1,
                  child: DropdownButton(
                    isExpanded: true,
                    underline: Text(''),
                    hint: Text('文体类型'),
                    value: state.typeValue,
                    items: typeItemList(),
                    onChanged: (item) {},
                  ),
                ),
                SizedBox(width: 10),
                Expanded(
                  flex: 1,
                  child: DropdownButton(
                    isExpanded: true,
                    underline: Text(''),
                    hint: Text('年级'),
                    value: state.gradeValue,
                    items: gradeItemList(),
                    onChanged: (item) {},
                  ),
                ),
                Expanded(
                  flex: 1,
                  child: DropdownButton(
                    isExpanded: true,
                    underline: Text(''),
                    hint: Text('文体类型'),
                    value: state.typeValue,
                    items: typeItemList(),
                    onChanged: (item) {},
                  ),
                ),
                SizedBox(width: 10),
                Expanded(
                  flex: 1,
                  child: DropdownButton(
                    isExpanded: true,
                    underline: Text(''),
                    hint: Text('年级'),
                    value: state.gradeValue,
                    items: gradeItemList(),
                    onChanged: (item) {},
                  ),
                ),
                SizedBox(width: 10),
              ],
            ),
            Expanded(child: viewService.buildComponent('public')),
          ],
        ),
        viewService.buildComponent('private'),
      ],
    ),
  );
}
